package sugarbind_input

class Author_Article {

	boolean is_Primary
	boolean is_Last
	Integer author_Rank
	String organization
	
    static constraints = {
		author(unique: ['article'])
		author_Rank(nullable:false)
		is_Primary(nullable:false)
		is_Last(nullable:false)
		organization(nullable:true)
    }
	static hasOne = [author:Author, article:Article]
	
	static mapping = {
//		id column: 'author_article_id'
		id generator: 'sequence', params: [sequence: 'author_article_id_seq']
	}
	
	public String toString(){
		int displayLength = 80
		String short_Title = article.title
		String primary = "";
		String last = "";
		if(is_Primary){primary = "(+)"}
		if(is_Last){last = "(**)"}
		
		if(short_Title.length()>displayLength)
		{
			short_Title=short_Title.substring(0, displayLength)
		}
		author.last_Name + " " + author_Rank + " "  + primary + last + " / " + "(" + article.pub_Year + ") " + short_Title+ "..."
	}
	
}
